In [1]:
import os
os.environ['DATA_PATH'] = 'E:/code/tgtrader/data/akshare_data.db'
In [2]:
from tgtrader.utils.duckdb_query import DuckDBQuery
from tgtrader.common import DataSource
In [3]:
data_source = DataSource.Akshare
db_query = DuckDBQuery(data_source)
In [4]:
sql = "select count(1) from t_kdata"
df = db_query.fetch_df(sql)
In [5]:
sql = "select substr(date, 1, 7) as month, count(distinct code) as count from t_kdata group by month order by month"
df = db_query.fetch_df(sql)
df
Out[5]:
month count
0 2010-01 1692
1 2010-02 1722
2 2010-03 1750
3 2010-04 1777
4 2010-05 1795
... ... ...
175 2024-08 5346
176 2024-09 5351
177 2024-10 5362
178 2024-11 5372
179 2024-12 5380

180 rows × 2 columns

In [6]:
# plotly
import plotly.express as px
fig = px.line(df, x='month', y='count', title='每月股票数量')
fig.show()